<template>
  <el-dialog
    :title="!dataForm.taskId ? '新增' : '详情'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <!-- :rules="dataRule" -->
    <el-form
      :model="dataForm"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item label="项目名称:" prop="projectId">{{
        dataForm.projectName
      }}</el-form-item>
      <el-form-item label="任务名称:" prop="projectId">{{
        dataForm.taskName
      }}</el-form-item>
      <el-form-item label="当前状态:" prop="projectId">{{
        taskStatusList[dataForm.taskStatus]
      }}</el-form-item>
      <el-form-item label="开始时间:" prop="projectId">{{
        dataForm.beginTime
      }}</el-form-item>
      <el-form-item label="结束时间:" prop="projectId">{{
        dataForm.endTime
      }}</el-form-item>
    </el-form>
    <el-table :data="taskDetailData">
      <el-table-column
        property="createTime"
        label="日期"
        width="150"
      ></el-table-column>
      <el-table-column
        property="realName"
        label="创建人姓名"
        width="200"
      ></el-table-column>
      <el-table-column property="taskRecord" label="操作"></el-table-column>
      <el-table-column property="fileName" label="文件名称"></el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            size="small"
            @click="uploadHandle(scope.row.taskDetailId)"
            v-if="fileName != null"
            >下载</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <!-- <el-button type="primary" @click="dataFormSubmit()">确定</el-button> -->
    </span>
  </el-dialog>
</template>

<script>
import { treeDataTranslate } from "@/utils";
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        projectId: "",
        taskId: 0,
        projectId: "",
        beginTime: "",
        endTime: "",
        taskName: "",
        taskDescription: "",
        dataListing: "",
        createUserId: "",
        taskStatus: "",
        allocateUserIds: "",
        headUerId: "",
        auditUserId: "",
      },
      taskDetailData: [],
      taskStatusList: {
        1: "进行中",
        2: "已提交",
        3: "延期",
        4: "已完成",
      },
      departList: [],
      departListTreeProps: {
        label: "departmentName",
        children: "children",
      },
      projectList: [],
      chk1: false,
    };
  },
  methods: {
    init(id) {
      this.dataForm.taskId = id || 0;
      // console.log(JSON.stringify(this.dataForm))

      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.taskId) {
          this.$http({
            url: this.$http.adornUrl(
              `/business/task/task-detail/${this.dataForm.taskId}`
            ),
            method: "get",
            params: this.$http.adornParams(),
          }).then(({ data }) => {
            if (data && data.code === 0) {
              // console.log(JSON.stringify(data));
              this.dataForm.projectId = data.taskDetail.projectId;
              this.dataForm.beginTime = data.taskDetail.beginTime;
              this.dataForm.endTime = data.taskDetail.endTime;
              this.dataForm.taskName = data.taskDetail.taskName;
              this.dataForm.projectName = data.taskDetail.projectName;
              this.dataForm.taskDescription = data.taskDetail.taskDescription;
              this.dataForm.dataListing = data.taskDetail.dataListing;
              this.dataForm.createUserId = data.taskDetail.createUserId;
              this.dataForm.taskStatus = data.taskDetail.taskStatus + "";

              this.taskDetailData = data.taskDetail.taskDetailVoList;
              console.log(JSON.stringify(this.taskDetailData));
            }
          });
        }
      });
    },
    uploadHandle(id) {
      console.log(id);
    },
  },
  // 菜单树选中
  departListTreeCurrentChangeHandle(data, node) {
    this.dataForm.parentId = data.id;
    this.dataForm.parentName = data.departmentName;
  },
  // 菜单树设置当前选中节点
  departListTreeSetCurrentNode() {
    this.$refs.departListTree.setCurrentKey(this.dataForm.parentId);
    this.dataForm.parentName = (this.$refs.departListTree.getCurrentNode() ||
      {})["departmentName"];
  },
  // 表单提交
  dataFormSubmit() {
    this.$refs["dataForm"].validate((valid) => {
      if (valid) {
        this.$http({
          url: this.$http.adornUrl(
            `/business/department/${!this.dataForm.id ? "save" : "update"}`
          ),
          method: "post",
          data: this.$http.adornData({
            id: this.dataForm.id || undefined,
            departmentName: this.dataForm.departmentName,
            parentId: this.dataForm.parentId,
          }),
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.visible = false;
                this.$emit("refreshDataList");
              },
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      }
    });
  },
};
</script>
